package cn.itcast.controller;

import cn.itcast.feign.pojo.Result;
import cn.itcast.feign.pojo.Room;


import cn.itcast.service.RoomService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/room")
public class RoomController {
    @Autowired
    private RoomService roomService;

    @PostMapping("/add")
    public Result save(@RequestBody Room room) {
        log.info("新增信息：{}", room);
        roomService.save(room);
        return Result.success();
    }

    @DeleteMapping("/{roomId}")
    public Result delete(@PathVariable Integer roomId) {
        log.info("根据id删除信息");
        roomService.delete(roomId);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Room room) {
        log.info("修改");
        roomService.update(room);
        return Result.success();
    }

    @PostMapping("/inquire")
    public Room select(@RequestBody Long roomId) {
        Room room = roomService.select(roomId);
        return room;
    }
}
